package cn.toma.controller;

import cn.toma.core.result.BaseApi;
import cn.toma.core.result.PageTool;
import cn.toma.core.result.Result;
import cn.toma.model.sys.Dict;
import cn.toma.service.sys.DictService;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;


/**
 * @author zqx
 * @version 1.0.0
 * @ClassName TestApi.java
 * @Description
 * @createTime 2019年09月24日 17:46:00
 */
@Api("测试接口")
@RestController
@RequestMapping("/test")
public class TestApi extends BaseApi
{


	@Autowired
	private DictService dictService;


	@ApiOperation("查找字典")
	@GetMapping("/dict/{fieldName}")
	public Result dictDetail(@PathVariable(name = "fieldName") String fieldName)
	{
		List<Dict> dictList = dictService.findFieldName(fieldName);
		return getSuccessObj(dictList);
	}

	@ApiOperation("新增字典")
	@PostMapping("/dict/insert")
	public Result insert(Dict dict)
	{
		try {
			dictService.save(dict);
			return getSuccessObj();
		} catch (Exception e) {
			e.printStackTrace();
			return getFailedObj();
		}
	}

	@ApiOperation("更新字典")
	@PutMapping("/dict/update")
	public Result update(Dict dict)
	{
		try {
			dictService.update(dict);
			return getSuccessObj();
		} catch (Exception e) {
			e.printStackTrace();
			return getFailedObj();
		}
	}


}
